package com.simon.adapter.base;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.widget.Toast;

import com.cmonbaby.adapter.RViewFactory;
import com.cmonbaby.adapter.RViewHelper;
import com.cmonbaby.adapter.pattern.RViewCreate;
import com.simon.adapter.R;

import java.util.List;

public abstract class BaseRViewActivity extends BaseActivity implements RViewCreate, RViewHelper.OnRecycleViewHelperListener {

    protected RViewHelper helper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        helper = RViewFactory.createRecycleViewHelper(this, this);
    }

    /** 创建SwipeRefresh下拉 */
    @Override
    public SwipeRefreshLayout createSwipeRefresh() {
        return (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    }

    /** 创建RecycleView */
    @Override
    public RecyclerView createRecyclerView() {
        return (RecyclerView) findViewById(R.id.recyclerView);
    }

    /** 创建RecycleView */
    @Override
    public LinearLayoutManager createLayoutManager() {
        return new LinearLayoutManager(this);
    }

    /** 创建RecycleView分割线 */
    @Override
    public RecyclerView.ItemDecoration createItemDecoration() {
        return new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
    }

    /** 创建空数据布局 */
    @Override
    public int createEmptyView() {
        return R.layout.empty_view;
    }

    /** 创建加载更多布局 */
    @Override
    public int createLoadMoreView() {
        return R.layout.default_loading;
    }

    /** 开始页码 */
    @Override
    public int startPageNumber() {
        return 1;
    }

    /** 最后一页少于多少条数据显示无更多数据 */
    @Override
    public int rowsPageNumber() {
        return 10;
    }

    /** 是否支持分页 */
    @Override
    public boolean isSupportPaging() {
        return false;
    }

    /** 加载更多 */
    @Override
    public void onLoadMore() {
    }

    /** 无更多数据 */
    @Override
    public void onNoMoreData() {
        Toast.makeText(this, "没有更多数据啦", Toast.LENGTH_SHORT).show();
    }

    /** 刷新适配器 */
    @Override
    public void notifyAdapterDataSetChanged(List data) {
        helper.notifyAdapterDataSetChanged(data);
    }
}
